<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>调代看课详情-云校通-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart style="background-color: #fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left">
	  		 <a href="<%=basePath %>/ls/teacher/change/course" href="javascript:;" class="icon icon-109 f-white">返回</a > 
	  		</div>
	    	<h1 class="weui-header-title">调代看课详情</h1>
	    </div>
		<div class="weui_tab_bd" style="padding-bottom: 95px;">
			<div class="weui_panel_bd">
                <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg">
                    <div class="weui_media_hd">
                        <img style="border-radius: 100%;" class="weui_media_appmsg_thumb" src="${config.imgUrl }${detail.headImgUrl}" alt="">
                    </div>
                    <div class="weui_media_bd">
                        <h4 class="weui_media_title">${detail.applyTeacherName }</h4>
                        <p class="weui_media_desc f-orange">${detail.nextStatusText }</p>
                    </div>
                </a>
			</div>
			
			<div class="weui_cells mt0">
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">事由：</span>${detail.reason }
					</div>
				</div>
			</div>
			<c:forEach var="item" items="${detail.itemList }" varStatus="status">
				<div class="weui_cells mt0">
					<div class="weui_media_fd  tright weui_btn_area">
	               		<div class="zhangtai" style="top: 2em; z-index: 500;">
	               			<span class="f-blue">
	               				<c:choose>
	               					<c:when test="${item.status == '001' || item.status == '004' }">
	               						<img class='img-max' src='<%=basePath %>/images/daish.png'>
	               					</c:when>
	               					<c:when test="${item.status == '002' || item.status == '000' }">
	               						<img class='img-max' src='<%=basePath %>/images/shenpitongguo.png'>
	               					</c:when>
	               					<c:when test="${item.status == '003' || item.status == '005' || item.status == '006'}">
	               						<img class='img-max' src='<%=basePath %>/images/shenpibohui.png'>
	               					</c:when>
	               				</c:choose>
	               			</span>
	               		</div>
	                </div>
					<div class="weui_cell xtbg-add-list-title">
						<div class="weui_cell_bd weui_cell_primary">
							<p class="f16 tdk-title">调代看课${status.index + 1 }</p>
						</div>
					</div>
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<span class="f-graybc">时间节次：</span> <fmt:formatDate type="date" value="${item.courseDate }" /> ${item.lesson }
						</div>
					</div>
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<span class="f-graybc">调代看课类型：</span> ${item.optionTypeText }
						</div>
					</div>
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<span class="f-graybc">班级：</span>${item.gradeName }（${item.clazz }）班
						</div>
					</div>
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<span class="f-graybc">课程：</span> ${item.subjectName }
						</div>
					</div>
					<div class="weui_cell">
						<c:choose>
							<c:when test="${item.hasExchangeTeacher == 0 && empty item.exchangeTeacherId && isAuditer > 0}">
								<div class="weui_cell_hd">
									<label class="weui_label"><span class="tdk-key">调代看老师</span></label>
								</div>
								<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
				                	<div class="searchbar_wrap">
				                		<div class="weui_search_bar">
				                			<form class="weui_search_outer">
				                				<div class="weui_search_inner">
				                					<i class="weui_icon_search"></i>
				                					<input type="search" class="weui_search_input" placeholder="请输入教师姓名">
				                					<i class="weui_icon_clear"></i>
				                				</div>
				                			</form>
				                		</div>
				                	</div>
									<div id="search-content" style="height: 100%; z-index: 10; transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);">
								       <div class="sb-content" style="position:inherit;overflow:scroll;"></div>
								    </div>
								    <input type="hidden" name="exchangeTeacherId" class="tdk-value">
								    <input type="hidden" name="exchangeTeacherName">
								    <input type="hidden" name="id" value="${item.id }"/>
				                </div>
							</c:when>
							<c:otherwise>
								<div class="weui_cell_bd weui_cell_primary">
									<span class="f-graybc">调代看教师：</span>
									<c:choose>
										<c:when test="${item.hasExchangeTeacher == 0 && empty item.exchangeTeacherId}">
											<span class="f-red">(需由教务处指派)</span>
										</c:when>
										<c:otherwise>
											${item.exchangeTeacherName }
											<c:if test="${item.hasExchangeTeacher == 0 }">
												<span class="f-red">(由教务处指派)</span>
											</c:if>
										</c:otherwise>
									</c:choose>
								</div>
							</c:otherwise>
						</c:choose>
					</div>
					<c:if test="${item.optionType == 1 }">
						<div class="weui_cell">
							<div class="weui_cell_bd weui_cell_primary">
								<span class="f-graybc">调课时间节次：</span><fmt:formatDate type="date" value="${item.exchangeCourseDate }" /> ${item.exchangeLesson }
							</div>
						</div>
						<div class="weui_cell">
							<div class="weui_cell_bd weui_cell_primary">
								<span class="f-graybc">调课课程：</span>${item.exchangeSubjectName }
							</div>
						</div>
					</c:if>
				</div>
			</c:forEach>
			
			<div class="weui_cells mt0">
				<div class="timeline">
				  	<ul>
				  		<c:forEach var="item" items="${detail.reqList }" varStatus="stat">
				  			<li class="timeline-item"> 
					   			<c:choose>
					   				<c:when test="${item.status == '000' || item.status == '002'}">
					   					<div class="timeline-item-head-first"> 
							  				<i class="weui_icon weui_icon_success_no_circle timeline-item-checked"></i> 
							  			</div> 
					   				</c:when>
					   				<c:when test="${item.status == '001' || item.status == '004' }">
					   					<div class=""> 
							   				<img class="gzsp-timeline-flow-img" src="<%=basePath %>/images/wait_icno.png">
							   			</div> 
					   				</c:when>
					   				<c:when test="${item.status == '003' || item.status == '005' || item.status == '006'}">
					   					<div class=""> 
							   				<img class="gzsp-timeline-flow-img" src="<%=basePath %>/images/bohuishenqing@3x.png">
							   			</div> 
					   				</c:when>
					   			</c:choose>
					   			<c:if test="${!stat.last}">
					   				<div class="timeline-item-tail" style="top: 25px;"></div> 
					   			</c:if>
					   			<div class="timeline-item-content">
					   				<div class="weui_panel_bd gzsp-timeline-flow">
						                <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg">
						                    <div class="weui_media_hd">
						                        <img style="border-radius: 100%;" class="weui_media_appmsg_thumb" src="${config.imgUrl }${item.headImgUrl}" alt="">
						                    </div>
						                    <div class="weui_media_bd">
						                        <h4 class="weui_media_title">${item.teacherName }</h4>
						                        <p class="weui_media_desc">
						                        	<c:if test="${item.status == '000' || item.status == '002'}"><span class="f-green">${item.statusText }</span></c:if>
	                        						<c:if test="${item.status == '001' }"><span class="f-yellow2">发起申请</span></c:if>
	                        						<c:if test="${item.status == '004' }"><span class="f-blue">${item.statusText }</span></c:if>
	                        						<c:if test="${item.status == '003' || item.status == '005' || item.status == '006' }"><span class="f-red">${item.statusText }</span></c:if>
						                        </p>
						                        <c:if test="${item.status == '003' || item.status == '005' || item.status == '006'}">
						                        	<p class="weui_media_desc" style="-webkit-line-clamp: inherit;">驳回原因：${item.rejectReason }</p>
						                        </c:if>
						                    </div>
						                </a>
									</div>
					   			</div> 
					   		</li>
				  		</c:forEach>
				     </ul> 
				</div>
			</div>
		</div>
	</div>
	<c:if test="${isAuditer > 0}">
		<c:choose>
			<c:when test="${detail.status == '000' }">
				<section class="weui-menu">
			        <div class="weui-menu-inner" id="cancelSubmit">
			            <span>撤销</span>
			        </div>
			    </section>
			</c:when>
			<c:when test="${detail.status == '004' }">
				<section class="weui-menu">
			        <div class="weui-menu-inner" id="rejectSubmit">
			            <span>驳回</span>
			        </div>
			        <div class="weui-menu-inner" id="agreeSubmit">
			            <span>同意</span>
			        </div>
			    </section>
			</c:when>
			<c:otherwise>
				<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
			</c:otherwise>
		</c:choose>
	    
	    <!--弹窗-->				
		<div class="weui_mask ueureiu weui_mask_visible" style="display: none;z-index:600">
		</div>
		<!--End弹窗-->
		<div class="weui_dialog weui_dialog_visible" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);display:none;z-index:700;">
			<div class="weui_dialog_hd">
				<strong class="weui_dialog_title">请输入驳回原因</strong>
			</div>
			<div class="weui_dialog_bd">
				<textarea class="weui-prompt-input" style="height: 80px;width: 95%;" rows="10" id="rejectText"></textarea>
			</div>
			<div class="weui_dialog_ft">
				<a href="javascript:;" id="rejectCancel" class="weui_btn_dialog default">取消</a>
				<a href="javascript:;" id="rejectSure" class="weui_btn_dialog primary">确定</a>
			</div>
		</div>
		<script>
			$(function() {
				$(".weui_search_input").bind('input propertychange', function() {  
				   queryStudentItem($(this));
			    });
		      	$("#agreeSubmit").click(function() {
		      		$.confirm("您确定审批通过吗?","", function() {
		      			agreeSubmit();
		            }, function() {
		                //取消操作
		            });
		      	})
		      	$("#cancelSubmit").click(function() {
		      		$.confirm("您确定撤销申请吗?","", function() {
		      			var params = {
      		  				id: "${detail.id}",
      		      			prevStatus: "${detail.status}",
      		      		}
		      			cancelSubmit(params);
		            }, function() {
		                //取消操作
		            });
		      	})
		      	$("#rejectSubmit").click(function() {
	      			$(".weui_mask").addClass("weui_mask_visible").show();
	      			$(".weui_dialog").addClass("weui_dialog_visible").show();
	      			$("#rejectCancel").click(function(){
	      				$("#rejectText").val(null);
	      				$(".weui_mask").hide();
	      				$(".weui_dialog").hide();
	      			});
	      			$("#rejectSure").click(function(){
	      				var text = $("#rejectText").val();
	      				if(text.trim().length > 0) {
	      		      		var params = {
	      		  				id: "${detail.id}",
	      		      			rejectReason: text,
	      		      			prevStatus: "${detail.status}"
	      		      		}
	      		      		replySubmit(params);
		      		      	$(".weui_mask").hide();
		      				$(".weui_dialog").hide();
		      				$("#rejectText").val(null);
	      		      	}
	      			});
		      	})
			});
			function replySubmit(params) {
				$.ajax({
		          	url : basePath + "/ls/teacher/change/course/audit/reject",
		  	 		type : "post",
		  	 		dataType : "json",
		  	 		data : params,
		            success: function(data){
		            	if(data.code == '000') {
		            		$.toast("提交成功！");
		            		setTimeout(function() {
		            			window.location.reload();
		            		}, 1000);
		            		return;
		            	}
		            	$.toptips(data.msg);
		            },
		            error: function(xhr, type){
		            	$.toptips("系统异常");
		            }
		         });
			}
			function cancelSubmit(params) {
				$.ajax({
		          	url : basePath + "/ls/teacher/change/course/audit/cancel",
		  	 		type : "post",
		  	 		dataType : "json",
		  	 		data : params,
		            success: function(data){
		            	if(data.code == '000') {
		            		$.toast("提交成功！");
		            		setTimeout(function() {
		            			window.location.reload();
		            		}, 1000);
		            		return;
		            	}
		            	$.toptips(data.msg);
		            },
		            error: function(xhr, type){
		            	$.toptips("系统异常");
		            }
		         });
			}
			function agreeSubmit() {
				var itemTemplate = {
					id: null,
					exchangeTeacherId: null,
					exchangeTeacherName: null
				}
				var paramList = [];
				var tdkList = $(".tdk-value");
				var isOk = true;
				for(var i = 0; i < tdkList.length; i++) {
					var itemObj = clone(itemTemplate);
					var v = $(tdkList[i]);
					var parent = v.closest(".weui_cells");
					if(v.val() == "") {
						$.alert(parent.find(".tdk-title").html()+"请指派教师");
						isOk = false;
						break;
					}
					if(isOk) {
						itemObj[v[0].name] = emptyToNull(v.val());
						itemObj[v.next()[0].name] = emptyToNull(v.next().val());
						itemObj[v.next().next()[0].name] = emptyToNull(v.next().next().val());
						paramList.push(itemObj)
					}
				}
				if(!isOk) return;
				var obj = {
					id: "${detail.id}",
					prevStatus: "${detail.status}",
					list: paramList
				};
				$.ajax({
					url: basePath + '/ls/teacher/change/course/audit/success',
					type: 'post',
					dataType: 'json',
					headers: {
						'Accept': 'application/json',
						'Content-Type': "application/json"
					},
					data : JSON.stringify(obj),
					success: function(data) {
						if(data.code == '000') {
							$.toast("提交成功");
							setTimeout(function() {
								window.location.reload();
		            		}, 1000);
						}else {
							$.toptips(data.msg);
						}
					},
		            error: function(xhr, type){
		            	$.toptips("系统异常");
		            }
				});
			}
			var search = false;
			function queryStudentItem(thiz) {
				keyword = thiz.val();
				if(keyword != null) {
					if(!/^[\u4E00-\u9FA5]+$/.test(keyword)) return;
					if(search) return;
					search = true;
				}
				$.ajax({
					url: basePath + "/ls/teacher/manage/keyword",
					type: 'POST',
					dataType : "json",
					data: {
						teacherName: keyword
					},
					success: function(data) {
						search = false;
						var html = "";
						if (data != null && data.length > 0) {
							for(var i in data) {
								var itm = data[i];
								html += '<div class="weui_cell"><p onclick=choseStudent(this,'+itm.id+',"'+itm.name+'")>'+ itm.name + '</p></div>';
							}
						}
						thiz.closest(".weui_cell_bd").find(".sb-content").html(html)
					},
					error: function(data) {
						$.alert("系统异常,请联系管理员","");
					}
				})
			}
			function choseStudent(thiz, studentId, studentName) {
				var parent = $(thiz).closest(".weui_cell_bd");
				parent.find(".weui_search_input").val(studentName);
				parent.find(".sb-content").html('');
				parent.find(".search-content").hide();
				parent.find("input[name='exchangeTeacherId']").val(studentId);
				parent.find("input[name='exchangeTeacherName']").val(studentName);
			}
		</script>
	</c:if>
	<c:if test="${isAuditer <= 0}">
		<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
	</c:if>
</body>
<script>
	
	
</script>
</html>